import React, { Component } from 'react'

export default class Controlled extends Component {
  state = {
    txt: '',
    isChecked: ''
  }
  render() {
    return (
      <div>
        <input
          type="text"
          value={this.state.txt}
          name="txt"
          onChange={(e) => this.inputChange(e)}
        />
        <input
          type="checkbox"
          value={this.state.isChecked}
          name="isChecked"
          onChange={(e) => this.inputChange(e)}
        />
      </div>
    )
  }

  inputChange(e) {
    let target = e.target
    let value = target.type == 'checkbox' ? target.checked : target.value
    this.setState({
      [e.target.name]: value
    })
  }
}
